<template>
	<view class="page padding">

		<wanl-schedule v-if="show" format="" @change="onChange" @choose="onChoose" ref="calendar"
			:data="dataList"></wanl-schedule>
		<view class="tip">注：是否有号以医院实际安排为准</view>
		<u-modal :show-cancel-button="true" v-model="hidden" :content="content" @confirm="confirm" ref="uModal"></u-modal>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				hidden: false,
				content:"当前暂无档期，是否添加档期？",
				dataList: [],
				show: false,
				times: {
					year:'',
					month:'',
					day:''
				}
			}
		},
		computed: {
			...mapState(['user', 'common'])
		},
		onLoad() {
			this.loadData()
		},
		methods: {
			async loadData(k) {
				await uni.request({
					url: '/addons/internethospital/api.doctor/scheduling',
					method: 'POST',
					success: res => {
						this.dataList = res.data;
						this.show = true
						if(k) {
							this.$refs.calendar.refresh()
						}
					}
				});

			},
			onChange(e) {
				// console.log(e);
			},
			onChoose(e) {
				// console.log(e)
				if (e.data) {
					// 有号
				} else {
					// 无号
					// let date = e.date.split('/');
					// this.times = {year:date[0],month:date[1],day:date[2]}
					// this.hidden = true
				}
			},
			async confirm() {
				let t = `{${this.times.month}: {${this.times.day}: 3}}`;
				let params = {
					doctor_id: 1,
					year: this.times.year,
					times: eval("(" + t + ")")
				}
				await uni.request({
					url: '/addons/internethospital/api.doctor/add_scheduling',
					method: 'POST',
					data:params,
					success: res => {
						console.log(res)
						this.$wanlshop.msg(res.msg)
						this.loadData(1)
					}
				});
			}
		}
	}
</script>

<style lang="less" scoped>
	page {
		background-color: #fff;
	}

	.tip {
		color: #9a9a9a;
		font-size: 26rpx;
	}
</style>